package com.xkdx.guangguang.fragment.newsinfo;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.xkdx.guangguang.module.network.AbsModule;
import com.xkdx.guangguang.shareclass.HomeListInfoDetail;
import com.xkdx.guangguang.shareclass.ShopAndBrandNewProduct;

public class DiscountModule extends AbsModule {
	ShopAndBrandNewProduct shopAndBrandNewProduct;

	@Override
	public void parseData() throws Exception {
		backJson = (JSONArray) result;
		try {
			for (int i = 0; i < backJson.length(); i++) {
				jsonObj = (JSONObject) backJson.get(i);
				String sortOfAct = jsonObj.getString("Act");
				if (sortOfAct.equals("getInfoDetail")) {
					shopAndBrandNewProduct = parseNewProduct(jsonObj.getJSONObject("Content"));
				}

			}
		} catch (Exception e) {
			// TODO: handle exception
		}

	}

	private ShopAndBrandNewProduct parseNewProduct(JSONObject person) throws Exception {
		ShopAndBrandNewProduct shopNewProduct = new ShopAndBrandNewProduct();
		try {
			if (person == null) {
				return shopNewProduct;
			}
			JSONObject stut = (JSONObject) person.get("Result");
			JSONObject item = (JSONObject) stut.get("DetailInfo");
			List<String> list = new ArrayList<String>();
			shopNewProduct.setInfoID(item.getString("InfoID"));
			shopNewProduct.setInfoTitle(item.getString("InfoTitle"));
			shopNewProduct.setInfoContent(item.getString("InfoContent"));
			shopNewProduct.setBegintime(item.getString("BeginTime"));
			shopNewProduct.setEndTime(item.getString("EndTime"));
			shopNewProduct.setCollectCount(item.getString("CollectCount"));
			shopNewProduct.setCommentCount(item.getString("CommentCount"));
			JSONArray arry = (JSONArray) item.getJSONArray("PictureUrl");
			for (int i = 0; i < arry.length(); i++) {
				list.add(arry.getString(i));
			}
			shopNewProduct.setPictureUrlList(list);

			JSONArray listinfo = (JSONArray) stut.getJSONArray("ListInfo");
			ArrayList<HomeListInfoDetail> l = new ArrayList<HomeListInfoDetail>();
			for (int k = 0; k < listinfo.length(); k++) {
				JSONObject jDetail = (JSONObject) listinfo.opt(k);
				HomeListInfoDetail detail = new HomeListInfoDetail();
				detail.setShopID(jDetail.getString("ShopID"));
				detail.setShopName(jDetail.getString("ShopName"));
				detail.setBrandID(jDetail.getString("BrandID"));
				detail.setBrandName(jDetail.getString("BrandName"));
				detail.setAddress(jDetail.getString("Address"));
				detail.setPhone(jDetail.getString("Phone"));
				detail.setWebSiteUrl(jDetail.getString("WebSiteUrl"));
				detail.setShopType(jDetail.getString("ShopType"));
				l.add(detail);
			}
			shopNewProduct.setHomeListInfoDetail(l);
		} catch (Exception e) {
			throw e;
		}
		return shopNewProduct;
	}

}
